package com.aiyige.page.login.presenter;

import android.text.TextUtils;

import com.aiyige.MyApp;
import com.aiyige.R;
import com.aiyige.base.eventbus.EventLogin;
import com.aiyige.model.User;
import com.aiyige.page.login.ResetPasswordPage;
import com.aiyige.page.login.callbacks.ILoginCallBack;
import com.aiyige.page.login.model.IResetPasswordModel;
import com.aiyige.page.login.model.impl.ResetPasswordImplement;
import com.aiyige.page.login.view.IResetPasswordView;
import com.aiyige.utils.ToastX;
import com.vondear.rxtools.RxActivityTool;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by xiachao on 2017/8/15.
 */

public class ResetPasswordPresenter {
    private IResetPasswordModel mModel;
    private IResetPasswordView mView;
    /**
     * 把Activity的需要用到的model通过ILoginView接口传递到Presenter来
     * @param iResetPasswordView
     */
    public ResetPasswordPresenter(IResetPasswordView iResetPasswordView)
    {
        this.mView = iResetPasswordView;
        this.mModel = new ResetPasswordImplement();
        mModel.setView(mView);
    }

    public void netResetPassword()
    {
        if (TextUtils.isEmpty(mView.getPassword())) {
            ToastX.show(MyApp.getInstance().getString(R.string.password_empty));
            return;
        }
        mModel.resetPassword(mView.getCode(),mView.getMobile(), mView.getPassword(), new ILoginCallBack()
        {
            @Override
            public void success(User user) {
                ToastX.show(MyApp.getInstance().getString(R.string.reset_password_success));
                //SessionUtil.updateCurrentSession(session);
                EventBus.getDefault().post(new EventLogin(user));
                RxActivityTool.finishActivity(ResetPasswordPage.class);
            }

            @Override
            public void error(String errorCode) {
            }

        });
    }
}
